<template>
  <section>
    <div v-for="(item, index) in title" :key="index" @click="itemClick(index)">
      <span :class="index == activeIndex ? 'active' : ''">{{ item }}</span>
    </div>
  </section>
</template>
<script>
export default {
  name: "",
  props: {
    title: {
      type: String,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      activeIndex: 0
    };
  },
  methods: {
    itemClick(index) {
      this.activeIndex = index;
      this.$emit('tabClick', index);
    }
  }
};
</script>
<style scoped>
section {
  padding: 30px 20px;
  background: #fff;
}
section {
  display: flex;
  font-size: 15px;
}
section div {
  flex: 1;
  text-align: center;
}
section div span {
  padding: 10px;
}
.active {
  color: red;
  border-bottom: 2px solid red;
}
</style>
